package com.alisveris.dao;


import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import com.alisveris.pojo.UrunResimPojo;
import com.dbConnector.DataBaseConnector;

public class UrunListDao extends DataBaseConnector {

	
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	public List<UrunResimPojo> getUrunList () throws Exception{
		
		List<UrunResimPojo> urunInfo = new ArrayList<UrunResimPojo>();
		
		
		UrunResimPojo urunResimPojo = null;
		
	 	String selectSQL = "SELECT * FROM product_image i, product p where p.PRODUCT_IMAGE_ID=i.id";
   	 
    	PreparedStatement	preparedStatement=null;
    	
    	
    	try {
			getDBConnection();
			
			preparedStatement = getDbConnection().prepareStatement(selectSQL);
     					
			ResultSet resultSet = preparedStatement.executeQuery();				
				
			while(resultSet.next()){
			
				urunResimPojo= new UrunResimPojo();
				
				
				
				
				urunResimPojo.setImageUrl(resultSet.getString("IMAGE_URL"));
				urunResimPojo.setKod(resultSet.getString("KOD"));
				urunResimPojo.setIsmi(resultSet.getString("ISMI"));
				
				if(resultSet.getString("MIKTAR")!=null){				 
					int miktar =  Integer.parseInt(resultSet.getString("MIKTAR"));					
					urunResimPojo.setMiktar(miktar);				
				}
				
				if(resultSet.getString("TALEP_MIKTAR")!=null){				 
					int talepMiktari =  Integer.parseInt(resultSet.getString("TALEP_MIKTAR"));					
					urunResimPojo.setTalepMiktar(talepMiktari);				
				}
				
				if(resultSet.getString("FIYAT")!=null){				   
					float fiyat  = Float.parseFloat(resultSet.getString("FIYAT"));
					urunResimPojo.setFiyat(fiyat);					
				}
				
				 
				urunInfo.add(urunResimPojo);
				
			}
			
			
		} catch (SQLException e) {
			e.printStackTrace();
 
		} finally {
 
			if (preparedStatement != null) {
				preparedStatement.close();
			}
 
			if (getDbConnection() != null) {
				getDbConnection().close();
			}	 
		}
		
		
		
	  return urunInfo;	
	}
	 
}
